import $axios from '@/utils/request'

export const processSongs = songs => {
  if (!songs.length) {
    return Promise.resolve(songs)
  }
  return $axios({
    url: '/api/getSongsUrl',
    method: 'get',
    params: {
      mid: songs.map(song => song.mid)
    }
  }).then(res => {
    const map = res.result.map
    return songs
      .map(s => {
        s.url = map[s.mid]
        return s
      })
      .filter(s => {
        return s.url.indexOf('vkey') > -1
      })
  })
}

export const getLyric = song => {
  return $axios({
    url: '/api/getLyric',
    method: 'get',
    params: { mid: song.mid }
  })
    .then(res => {
      if (res.code === 0) {
        return res ? res.result.lyric : '[00:00]该歌曲暂时无法获取'
      }
    })
    .catch(() => {})
}
